import 'package:flutter/services.dart';
import 'package:xindong/common/xindong_all.dart';
import 'package:xindong/common/xindong_methods.dart';
import 'package:xindong/common/xindong_storage.dart';

class XinDongFromNativePlugin {
  void setupListen() {
    const channel = MethodChannel("com.xindong.zhitgx");
    channel.setMethodCallHandler((call) async {
      mDebugPrint("通道接收 ${call.method} ${call.arguments}");
      try {
        switch (call.method) {
          case "chaoLianData":
            {
              Map<String, dynamic> controlParams = Map.from(call.arguments ?? {});
              if (controlParams.containsKey("_scene_")) {
                String scene = controlParams["_scene_"].toString();
                if (scene == "install") {
                  if (controlParams.containsKey("send_code")) {
                    XinDongAll.instance.inviteCode = controlParams["send_code"];
                    XinDongStorage.instance.saveString(XinDongStorageKey.invite, XinDongAll.instance.inviteCode!);
                  }
                  return Future.value(true);
                }
              }
            }
            break;
        }
      } on PlatformException catch (e) {
        //mDebugPrint('错误：${e.toString()}');
        return Future.error(e.toString());
      }
    });
  }
}
